public class SelectSort {
    public static void main(String[] args) {
        int[] arr = {6,5,7,3,9,8,5,2};
        selectSort(arr);
        for (int n : arr) {
            System.out.println(n);
        }
    }

    private static void selectSort(int[] arr) {
        for (int i = 0; i < arr.length-1; i++) {
            int minNum = i;
            for (int j = i; j < arr.length; j++) {
                if (arr[j] < arr[minNum]) {
                    minNum = j;
                }
            }
            swap(arr, i, minNum);
        }
    }

    private static void swap(int[] arr, int i, int j) {
        int tmp = arr[i];
        arr[i] = arr[j];
        arr[j] = tmp;
    }
}
